package com.garrett.demo.sys.controller;

import com.garrett.demo.sys.entity.Account;
import com.garrett.demo.sys.entity.SimsStudent;
import com.garrett.demo.sys.entity.UserInfo;
import com.garrett.demo.sys.service.AccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: Garrett s.h.xjw@outlook.com
 * @date: 2021/1/29 22:44
 * @version: 1.0
 * @description: 系统授权
 */
@RestController
@RequestMapping("/auth")
@Api(tags = "系统：系统授权接口")
@Slf4j
@RequiredArgsConstructor
public class AuthorizationController {

    private final AccountService accountService;

    @PostMapping("login")
    public SimsStudent login(String username, String password){
        SimsStudent userInfo = accountService.checkLogin(username, password);

        return userInfo;
    }

    @PostMapping("/mobile/regist")
    public ResponseEntity<Object> mobileRegist(String username, String password) {
        if (Strings.isBlank(username) && Strings.isBlank(password)) {
            return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
        }
        Map<String, String> map = new HashMap<>();


        // 因为是用于移动端注册，用户体验上不应该让用户填写过多信息。
        // 模拟一下
        // 这一部分根据自己的实际业务设计哈 ---- begin
        Account a = new Account();
        a.setAccount(username);
        a.setPassword(password);
        SimsStudent s = new SimsStudent();
        s.setStudentId(username);
        accountService.createAccount(a,s);
        // 这一部分根据自己的实际业务设计哈 ---- end

        map.put("message","注册成功");
        return new ResponseEntity<>(map,HttpStatus.OK);
    }

    @ApiOperation("获取验证码")
    @GetMapping("getVerCode")
    public String message(){
        return new String("test");
    }

}
